package com.safe.first.application.service;

import com.safe.first.application.dto.cmd.CreateUserCmd;
import com.safe.first.common.service.AbstractService;
import com.safe.first.domain.user.User;
import com.safe.first.domain.user.factory.DefaultUserFactory;
import com.safe.first.domain.user.repo.UserRepo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author Mickey
 * @since 2022/6/17
 **/
@Service
@AllArgsConstructor
public class UserAppService extends AbstractService {

    private final UserRepo userRepo;
    private final DefaultUserFactory userFactory;

    public User byId(Long id) {
        return userRepo.byId(id).get();
    }

    public void create(CreateUserCmd createUser) {
        creatorFor(userRepo)
                .instance(() -> userFactory.instance(createUser))
                .call();

    }

}
